from typing import List

"""
Author: Gaoqiang Du
Description：将数据转换为markdown文本
Time: 2022/4/19 11:28
"""


def title_transform(title, level: int = 1):
    return "#" * level + " " + title + "\n"


def description_transform(desc):
    if desc:
        return desc + "\n"
    return ""


def req_method_transform(method: str):
    return title_transform("请求方式", 2) + "\n- " + method.upper() + "\n"


def res_example_transform(res_example: str):
    if res_example:
        md_str = "## 示例\n\n**返回示例**\n\n"
        return md_str + "```json\n" + res_example + "\n```\n"
    return ""


def table_transform(table: List[List[str]]) -> str:
    md_str = ""
    # 设定table头
    if table and table[0]:
        md_str += "| " + " | ".join(table[0]) + " |\n"
        md_str += "|" + " --- |" * len(table[0]) + "\n"
    # 设定table的每一行
    for line in table[1:]:
        md_str += "| " + " | ".join([str(i) for i in line]) + " |\n"

    return md_str


def get_req_params_md():
    return "## 请求参数\n"


def get_res_params_md():
    return "## 返回参数\n"
